<?php
/*******************************************************************************
 * @filename: payments_controller.php
 *
 * @author: immer_baldos
 *
 * @description: controller for payment model
 *
 * @history:
 *
 *   VERSION   DATE                   BY          NOTES
 *  ---------------------------------------------------------------
 *     1.0     September  9, 2009     immer       initial bake
 *
 *     2.0     September 12, 2009     immer       enable authetication
 *
 ******************************************************************************/
class PaymentsController extends AppController {

	var $name = 'Payments';
	var $helpers = array('Html', 'Form');
    var $components = array('Auth','Cookie', 'Session');

	function index() {
		$this->Payment->recursive = 0;
		$this->set('payments', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Payment.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('payment', $this->Payment->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Payment->create();
			if ($this->Payment->save($this->data)) {
				$this->Session->setFlash(__('The Payment has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Payment could not be saved. Please, try again.', true));
			}
		}
		$customers = $this->Payment->Customer->find('list');
		$orders = $this->Payment->Order->find('list');
		$this->set(compact('customers', 'orders'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Payment', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Payment->save($this->data)) {
				$this->Session->setFlash(__('The Payment has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Payment could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Payment->read(null, $id);
		}
		$customers = $this->Payment->Customer->find('list');
		$orders = $this->Payment->Order->find('list');
		$this->set(compact('customers','orders'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Payment', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Payment->del($id)) {
			$this->Session->setFlash(__('Payment deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}


}
?>